
import { useContext } from 'react'
import { bindActionCreators } from '../../redux'

// 获取上下文对象
import ReactReduxContext from '../ReactReduxContext'

/**
 * 官方源码中没有实现的一个 hook
 * 将 actionCreators 绑定到 dispatch 上返回对应的映射对象
 */
function useBoundDispatch(actionCreators) {
  const { store } = useContext(ReactReduxContext) // 获取上下文中的仓库中的状态
  const boundActionCreators = bindActionCreators(actionCreators, store.dispatch)
  return boundActionCreators
}

export default useBoundDispatch

